import request from '@/utils/request'
import newRequest from '@/utils/newRequest'
import { mergeParams } from '@/utils'

// 查询用户列表
export function listUser(query) {
  return request({
    url: '/api/v1/sysUserList',
    method: 'get',
    params: query
  })
}

export function newListUser(query) {
  const data = mergeParams(query)
  return newRequest({
    url: '/SYS/SYuser/doQueryPage',
    method: 'post',
    data
  })
}

export function newListRole(query) {
  const data = mergeParams(query)
  return newRequest({
    url: '/SYS/SYgroupH/doQueryPage',
    method: 'post',
    data
  })
}

export function listAllUser(query) {
  return request({
    url: '/api/v1/sysAllUserList',
    method: 'get',
    params: query
  })
}

export function listLeader(query) {
  return request({
    url: '/api/v1/sysUserLeaderList',
    method: 'get',
    params: query
  })
}

// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/api/v1/sysUser/' + userId,
    method: 'get'
  })
}

export function getUserInit() {
  return request({
    url: '/api/v1/sysUser/',
    method: 'get'
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/api/v1/sysUser',
    method: 'post',
    data: data
  })
}

export function newAddUser(query) {
  const data = mergeParams(query)
  return newRequest({
    url: '/SYS/SYuser/doSave',
    method: 'post',
    data
  })
}

// 修改用户
export function updateUser(data) {
  return request({
    url: '/api/v1/sysUser',
    method: 'put',
    data: data
  })
}

export function newUpdateUser(query) {
  const data = mergeParams(query)
  return newRequest({
    url: '/SYS/SYuser/doUpdate',
    method: 'put',
    data
  })
}

// 删除用户
export function delUser(userId) {
  return request({
    url: '/api/v1/sysUser/' + userId,
    method: 'delete'
  })
}

// 删除用户
export function newDelUser(userID) {
  const data = mergeParams({ userID })
  return newRequest({
    url: '/SYS/SYuser/doDelete',
    method: 'delete',
    data
  })
}

// 导出用户
export function exportUser(query) {
  return request({
    url: '/api/v1/sysUser/export',
    method: 'get',
    params: query
  })
}

// 用户密码重置
export function resetUserPwd(userId, password) {
  const data = {
    userId,
    password
  }
  return request({
    url: '/api/v1/sysUser',
    method: 'put',
    data: data
  })
}

export function newResetUserPwd(id, password) {
  const _data = {
    id,
    password
  }
  const data = mergeParams(_data)
  return newRequest({
    url: '/SYS/SYuser/doUpdatePass',
    method: 'post',
    data
  })
}

// 用户状态修改
export function changeUserStatus(userId, status) {
  const data = {
    userId,
    status
  }
  return request({
    url: '/api/v1/sysUser',
    method: 'put',
    data: data
  })
}

export function newDoOff(userID) {
  const data = mergeParams({ userID })
  return newRequest({
    url: '/SYS/SYuser/doOff',
    method: 'put',
    data
  })
}

export function newDoOpen(userID) {
  const data = mergeParams({ userID })
  return newRequest({
    url: '/SYS/SYuser/doOpen',
    method: 'put',
    data
  })
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/api/v1/user/profile',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/api/v1/sysUser/profile',
    method: 'put',
    data: data
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword, passwordType) {
  const data = {
    oldPassword,
    newPassword,
    passwordType
  }
  return request({
    url: '/api/v1/user/pwd',
    method: 'put',
    data: data
  })
}

// 用户密码批量重置
export function updateUsersDefaultPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/api/v1/user/setDefaultPwd',
    method: 'put',
    data: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/api/v1/user/avatar',
    method: 'post',
    data: data
  })
}

// 下载用户导入模板
export function importTemplate() {
  return request({
    url: '/api/v1/sysUser/importTemplate',
    method: 'get'
  })
}

// 获取用户信息
export function getUserInfo(params) {
  const data = mergeParams(params)
  return newRequest({
    url: '/SYS/SYuser/doQueryPage',
    method: 'post',
    data
  })
}

// 修改用户信息
export function editUserInfo(params) {
  const data = mergeParams(params)
  return newRequest({
    url: '/SYS/SYuser/doSave',
    method: 'post',
    data
  })
}

// 新增人员配置
export function doSaveGroup(params) {
  const data = mergeParams(params)
  return newRequest({
    url: '/SYS/SYuser/doSaveGroup',
    method: 'post',
    data
  })
}

// 查询人员配置
export function doQueryRoleUser(params) {
  const data = mergeParams(params)
  return newRequest({
    url: '/SYS/SYuser/doQueryRoleUser',
    method: 'post',
    data
  })
}
